
var app = angular.module("haircutApp", []).controller('haircutCtrl', function($scope, $http) {
	//定义理发信息对象
	$scope.data = {
		"haircut" : 1,
		"perm" : 1,
		"hairDye" : 1,
		"hairWash" : 1
	};
	//设置初始化人数
	setDefaultPeople();
	$scope.selectPeople = function(people) {
		//默认99代表更多，添加弹框
		if (people === "haircut_99") {
			//alert("请选择更多人");
		}
		var serviceKey = people.split("_")[0];
		var servicePeople = people.split("_")[1];
		$scope.data[serviceKey] = servicePeople;
		setSelectPeople(serviceKey, servicePeople);
		console.log("select people");
		console.log($scope.data);
	}

	//处理选中人数的状态
	function setSelectPeople(service, people) {
		switch (service) {
		case "haircut":
			$scope.isHaircut1 = false;
			$scope.isHaircut2 = false;
			$scope.isHaircut3 = false;
			$scope.isHaircut99 = false;
			break;
		case "perm":
			$scope.isPerm1 = false;
			$scope.isPerm2 = false;
			$scope.isPerm3 = false;
			$scope.isPerm99 = false;
			break;
		case "hairDye":
			$scope.isHairDye1 = false;
			$scope.isHairDye2 = false;
			$scope.isHairDye3 = false;
			$scope.isHairDye99 = false;
			break;
		case "hairWash":
			$scope.isHairWash1 = false;
			$scope.isHairWash2 = false;
			$scope.isHairWash3 = false;
			$scope.isHairWash99 = false;
			break;
		}

		//选择类型首字母大写
		service = service[0].toUpperCase() + service.substring(1);
		//拼接选中状态的对象
		var serviceTemp = "is" + service + people;
		$scope[serviceTemp] = true;

	}

	$scope.lineUpCommit = function() {}

	//初始化人数
	function setDefaultPeople() {
		//理发默认选中一人
		$scope.isHaircut1 = true;
		$scope.isHaircut2 = false;
		$scope.isHaircut3 = false;
		$scope.isHaircut99 = false;
		//烫发选中一人
		$scope.isPerm1 = true;
		$scope.isPerm2 = false;
		$scope.isPerm3 = false;
		$scope.isPerm99 = false;
		//染发选中一人
		$scope.isHairDye1 = true;
		$scope.isHairDye2 = false;
		$scope.isHairDye3 = false;
		$scope.isHairDye99 = false;
		//洗头选中一人
		$scope.isHairWash1 = true;
		$scope.isHairWash2 = false;
		$scope.isHairWash3 = false;
		$scope.isHairWash99 = false;
	}
	$scope.onSubmmit = function() {
		
		$http({
			url : 'www.baidu.com',
			method : 'POST',
			data :  dealRequestData($scope.data)
		}).then(function successCallback(response) {
			// 请求成功执行代码
			console.log(response);
		}, function errorCallback(response) {
			// 请求失败执行代码
			console.log(response);
		});
	}
	
	function dealRequestData(data){
		var requestData = [];
		requestData.push({"serviceCode":"1","personNum":data.haircut});
		requestData.push({"serviceCode":"2","personNum":data.perm});
		requestData.push({"serviceCode":"3","personNum":data.hairDye});
		requestData.push({"serviceCode":"4","personNum":data.hairWash});
		return requestData;
	}

});